package com.example.result;

import lombok.Data;

import java.io.Serializable;

/**
 * @Date 2022/9/6
 * @Description
 */
@Data
public class R implements Serializable {

    private Object data;
    private Integer code;
    private String msg;

    public static R success(Object data, String msg) {
        return success(data, Code.SUCCESS_CODE, msg);
    }

    public static R success(Object data, Integer code, String msg) {
        R r = new R();
        r.data = data;
        r.code = code;
        r.msg = msg;
        return r;
    }

    public static R fail(String msg) {
        return fail(null, Code.FAIL_CODE, msg);
    }

    public static R fail(Integer code, String msg) {
        return fail(null, code, msg);
    }

    public static R fail(Object data, String msg) {
        return fail(data, Code.FAIL_CODE, msg);
    }

    public static R fail(Object data, Integer code, String msg) {
        R r = new R();
        r.data = data;
        r.code = code;
        r.msg = msg;
        return r;
    }

}
